﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MyMusicList.DBModel;
using Tool;

namespace MyMusicList.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class UserController : ApiController
    {
        private DataDBContext _context;
        new BLL.User User = null;
        public UserController(DataDBContext context)
        {
            _context = context;
        }

        // GET: api/Address
        [HttpGet]
        public object Get()
        {
            User = new BLL.User(_context);
            var data = User.Get();
            if (data.Equals(false))
            {
                return ResultArray(data);
            }
            return ResultArray(data);
        }

        
        public object GetUser()
        {
            User = new BLL.User(_context);
            var data = User.Get();
            if (data.Equals(false))
            {
                return ResultArray(data);
            }
            return ResultArray(data);
        }

        //根据现有工具库版本，此为最大限度的优化
        // GET: api/Address/5
        [HttpGet("{id}")]
        public object Get(int id)
        {
            User = new BLL.User(_context);
            var data = User.GetId(id);
            if (data.Equals(false))
            {
                return ResultArray(data);
            }
            return ResultArray(data);
        }

        // POST: api/Address
        [HttpPost]
        public object Post(DBModel.User value)
        {
            //AddressValidate addressValidate = new AddressValidate();
            //var address1 = addressValidate.getProperties<Address>(value);

            //模拟php的验证成功
            User = new BLL.User(_context);
            var data = User.post(value);
            if (data.Equals(false))
            {
                return ResultArray(data);
            }
            return ResultArray(data);

        }

        // PUT: api/Address/5
        [HttpPut("{id}")]
        public object Put(int id, DBModel.User value)
        {
            User = new BLL.User(_context);
            var data = User.put(id, value);
            if (data.Equals(false))
            {
                return ResultArray(data);
            }
            return ResultArray(data);
        }

        // DELETE: api/ApiWithActions/5
        [HttpDelete("{id}")]
        public object Delete(int id)
        {
            User = new BLL.User(_context);
            var data = User.Delete(id);
            if (data.Equals(false))
            {
                return ResultArray(data);
            }
            return ResultArray(data);
        }
    }
}